package com.nf.practice.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@PropertySource({"classpath:application.yml"})
public class Swagger2Config {

        public static final String SWAGGER2_SCAN_BASE_PACKAGE = "com.nf.practice.controller";
        public static final String VERSION = "1.0.0";

        @Value("${swagger.enable}")
        private boolean enable;
        @Bean
        public Docket createResetApi(){

            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(webApiInfo())
                    .enable(enable)
                    .select()
                    .apis(RequestHandlerSelectors.basePackage(SWAGGER2_SCAN_BASE_PACKAGE))
                    .paths(PathSelectors.any())
                    .build();
        }


        private ApiInfo webApiInfo(){
            // 设置标题，文档描述,版本
            return new ApiInfoBuilder()
                    .title("测试Demo")
                    .description("测试Demo接口")
                    .version(VERSION)
                    .contact(new Contact("bboy","www.baidu.com","bboyxiaopeng@centaline.com.cn"))
                    .build();
        }

}
